'use strict';

const _ = require('lodash');


merchantController.$inject = ['merchantService','$uibModal'];

function merchantController(merchantService , $uibModal) {

  var vm = this;

  vm.auditedlist = [];
  vm.unauditedlist = [];
  vm.registeredlist = [];

  merchantService.getListsBystatus("1").then(function (res) {
    vm.auditedlist = res.data
  }).catch(err => console.log(err)); 

  merchantService.getListsBystatus("0").then(function (res) {
    vm.unauditedlist = res.data
  }).catch(err => console.log(err));  

  merchantService.getAlls().then(function (res) {
    vm.registeredlist = res.data;
  }).catch(err => console.log(err));

  vm.block = function(_id,index){
    let merchant = vm.auditedlist[index];
    let status2 = merchant.status2;
    let status = (status2=="1")?"0":"1";
    merchantService.block(merchant, status).then(function(res){
         vm.auditedlist[index] = res.data;
    }).catch(err => console.log(err))
  };

  vm.pass = function(index){
    let id = vm.unauditedlist[index]._id;
    merchantService.pass(id).then(function(res){
        vm.unauditedlist.splice(index,1);
    }).catch(err => console.log(err));
  };

  vm.reject = function(index){
    let id = vm.unauditedlist[index]._id;
    let reason = vm.unauditedlist[index].rejectRea;
    merchantService.reject(id, reason).then(function(res){
       vm.unauditedlist.splice(index,1);
    }).catch(err => console.log(err))
  }


  // var socket = io.connect('http://127.0.0.1:8999'); 
  //   socket.on('nameResult', function(result) {
  //       var message;
  //       if (result.success) {
  //           message = 'you are now known as ' + result.name + '.'; 
  //           console.log('message=', message);
  //           document.getElementById('guestname').innerHTML = message;
  //       } else {
  //           message = result.message;
  //       }
  //   });

  //   socket.on('joinResult', function(result) {
  //       document.getElementById('room').innerHTML = result.room;
  //   });


  //   $scope.sendMessage = function() {
  //       var message = {
  //           room: 'Lobby',
  //           text: document.getElementById('user_input').value
  //       };
  //       socket.emit('message', message);
  //   };

  //   socket.on('message', function(message) {
  //       var p = document.createElement('p');
  //       p.innerHTML = message.text;
  //       document.getElementById('message').appendChild(p);
  //   });


  // vm.openmodal = function(index){
  //   console.log(index)
  //   rejectindex = index
  //   var modalInstace = $uibModal.open({
  //       template: require('../templates/modaltemplates/rejectmodal.html'),
  //       controller: 'merchantController',
  //       resolve:{
  //         index : index
  //       }
  //   });
  // }

}
module.exports = merchantController;